<?php
/**
 * 主动请求企业微信接口封装
 * Created by PhpStorm.
 * User: sh01
 * Date: 2018/1/9
 * Time: 9:26
 */

namespace corpWeixin;
use corpWeixin\corpWeixinSdk\CWXTool;
use corpWeixin\corpWeixinSdk\Curl;


class CWXDepartment
{
    /**
     * 获取指定部门及它的子部门列表
     * @param string $id //为空则获取全部组织架构
     * @return mixed
     */
    public function findTree($id='')
    {
        /* @var $cwxTool \corpWeixin\corpWeixinSdk\CWXTool*/
        $cwxTool = CWXTool::getInstance();
        $url = 'https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token='.$cwxTool->getAccessToken().'&id='.$id;
        $res = json_decode(Curl::httpGet($url),true);
        if(isset($res['errcode']) && $res['errcode']===0)
            return $res['department'];
        return false;
    }
}